Hello and welcome.
In this video we are going to create the logic that or make the calculator work.
So let's create a new file that we use to write arjan Us crypt code.
So this is hastier mouse.
I'm just going to click on the file option here and click on new file.
And I'm going to save this file save that's inside the directory codes on calculator and save these
as loan calculator.
DOT.
Yes.
Make sure and the drop down.
I am going to select javascript save.
So any code that here now will be a jab ask crip could o key to the function.
I'm going to create.
I'm going to call it compute loan because I've already made references to it here inside my hastier
male code.
So are typing the word function to create a function do function space followed by the name of the function
and the function is going to be called compute.
Not is used Come all case which means the first letter is the word case and the first of the next word
is upper case.
Next I need to place parentheses and then curly braces and separate the curly braces in between the
brace this is where will add the logic for the loan.
The first thing I want to do.
I'm going to add some variables.
So let me run through the variables with you on line 3 quick to variable kord amount.
This would be this would represent the amount of long that you want to borrow and set it to court documents
or get eliminated.
And past them the idea of Mt..
If you're wondering where I got this idea for values from is from the hastier melon side of things so
here we've got on the court amount.
So that's what I'm referring to here.
They did deduct value basically refers to the value that you would input as the amount line for a variable
caught interest on an offset that equals to the document.
Get element back.
And the idea is interests.
What does your rate so whatever value we have the interest rate is going to grab that too.
Again I go into my hatim millercoors see we've gotten a Deek award interest on that score ricked that's
what is referring to like fire.
Got a variable quad months in.
This is equal to the document.
Get eliminated by a T and the idea is months.
Can we have any value that is entered for that value for that month or be attached to the variable.
So if we come in a game we have quite an idea chord and once that's what he's referring to.
Here we've got a variable called interest.
So this is going to represent the actual interest so the interest on the loan is going to be the amount
which is one variable times the interest on does rate time during one.
Any time you have values surrounded by parenthetic values are computed first so it would do the interest
rate times.
Or Point 1 first before the deviation and the multiplication.
Okay so the point 1 basically gives it a two decimal places so you'd have two decimals after the figure
line 7.
Here are quite a variable called payment and this variable is going to be caused to the amount we represent
the monthly payment that the loan borrower have to pay.
So is going to equal the amount divided by the months plus the interest.
And then here we have tashkin Ditto fixed method bisley.
This enables you to have two decimal places or two numbers after the decimal place.
That's what that is for.
Next we'll get into a line of code that will be a rep repress possible for putting commas on numbers
for three digits.
So if we look triggered value and then place a comma after every three digit.
Someone to try and explain this line it as much as I can hear the pain men physically here is equal
to the pain meant to string busways converting value to string.
And then we replace it.
This is going to convert it into money.
Format's going to convert the font format into money and doing that using this replace method.
And inside the replacement here we've got these values are trying to explain these as much as I can
this slash be here basically is used to look within a word boundary.
And what that means is that it can't be part of another type of work has come of a pattern.
It has to look for.
And then this here this question mark.
Basically the question mark I'm equal to tells it to find what the group is looking for.
For example it will look for issues in these last three here to look for three digits so it will look
for any three digits in a row and then place a comma there.
Plus this plus basically marks the three digits wrapped in parentheses to make sure that is treated
as a block of three so basically helps to repeat the pattern.
So he knows where to place the comma after every three digits I've added another block another line
of call line line here line basically is going to be responsible for displaying the output.
So he's going to say document using the documentor get them in a method method and we grab grabbing
the idea which is this here.
This idea here this page to talk to is going to grab that.
This is where it all inject the result of the computer and loan repayment.
So to grab that and it will replace that Deve the content of it with this dot in his email and the value
of this in his tim is this here.
So now I'll put inside the TV here.
It will outport the word monthly payment.
It would then give the value of the monthly payment which is going to be in dollars plus the payment.
Okay.
So that's where it's going to do.
So I'm just going to save that file and save all up and I'll go into my direct freely which is this
and just double click on the loan calculator or hastier mail to run the application.
So let's quickly test it.
Let's see.
I want to borrow 10000.
You can either input the value or you can use this to Anglosphere to move it forward.
So I'm going to put in ten thousand.
And let's say the interest rate on that is 10 percent.
Let's say one borrowed out of 12 months.
This is what I'm going to repay eproms want I want six point six seven so these values are changeable.
So feel free to play around with the values to test the app.
So that's basically it.
And we've got the main functionality of the app work in the next lecture.
I'm just going to add some success to make it look a bit nicer.
So that's it for this lecture.
Thank you for watching.
Bye for now.